<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager" %>
<!DOCTYPE html>
<html lang="zh-cn">
<c:set var="text" value="添加"/>
<c:if test="${role.id>0}">
    <c:set var="text" value="修改"/>
</c:if>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>${text}角色信息</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/front/css/bootstrap.min.css"/>
</head>
<body>
<%@include file="/inc/menu.jsp"%>
<nav class="permission-nav">
    <div class="container-fluid">
        <div class="main-content">
            <div class="row">
                <div class="col-sm-12">
                    <ul class="nav nav-tabs nav-3rd">
                        <li><span>角色管理</span></li>
                        <li><a href="${pageContext.request.contextPath}/admin/role/list">角色列表</a></li>
                        <li class="active">${text}角色信息</li>
                    </ul>
                </div>
            </div>
            <div class="inner-content inner-content-left">
                <form id="editForm" class="material-edit" name="role"
                      action="${pageContext.request.contextPath}/admin/role/edit"
                      method="post">
                    <div class="hidden">
                        <input type="hidden" name="id" value="${role.id}"/><br/>
                        <input type="hidden" name="oldName" value="${role.name}"/>
                    </div>
                    <div class="form-group">
                        <label>name(唯一)<span class="required">*</span></label>

                        <div>
                            <label>角色名</label>
                            <input class="form-control" type="text" name="name" value="${role.name}" autofocus
                                   required/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>权限</label>

                        <div>
                            <div class="input-group">
                                <%--根资源--rootResourceDto---%>
                                <ul>
                                    <li>
                                        <label class="drop-down"> <input type="checkbox"
                                                <c:if test="${rootResourceDto.isSelected}">
                                                    checked
                                                </c:if>
                                                /> ${rootResourceDto.resource.cnName}</label>
                                        <%--如果有二级资源--%>
                                        <c:forEach items="${rootResourceDto.subResourceDto}" var="res2Dto">
                                            <ul>
                                                <li>
                                                    <label class="drop-down"> <input type="checkbox"
                                                            <c:if test="${res2Dto.isSelected}">
                                                                checked
                                                            </c:if>
                                                            />${res2Dto.resource.cnName}
                                                    </label>
                                                        <%--如果有三级资源  --%>
                                                    <c:forEach items="${res2Dto.subResourceDto}" var="res3Dto">
                                                        <ul>
                                                            <li>
                                                                <label class="drop-down"> <input type="checkbox"
                                                                        <c:if test="${res3Dto.isSelected}">
                                                                            checked
                                                                        </c:if>
                                                                        />${res3Dto.resource.cnName}</label>
                                                                <c:forEach
                                                                        items="${res3Dto.resource.resourcePermissionList}"
                                                                        var="rp3">
                                                                    <%--三级资源的权限  --%>
                                                                    <ul>
                                                                        <li><label> <input type="checkbox" name="rpids"
                                                                                <c:if test="${role.resourcePermissionList.contains(rp3)}">
                                                                                    checked
                                                                                </c:if>
                                                                                value="${rp3.id}"/>${rp3.permission.name}
                                                                        </label></li>
                                                                    </ul>
                                                                </c:forEach>
                                                            </li>
                                                        </ul>
                                                    </c:forEach>
                                                    <c:forEach items="${res2Dto.resource.resourcePermissionList}" var="rp2">
                                                        <%--如果没有子资源的，也可以有权限--%>
                                                        <ul>
                                                            <li><label> <input type="checkbox" name="rpids"
                                                                    <c:if test="${role.resourcePermissionList.contains(rp2)}">
                                                                        checked
                                                                    </c:if>
                                                                    value="${rp2.id}"/>${rp2.permission.name}
                                                            </label></li>
                                                        </ul>
                                                    </c:forEach>
                                                </li>
                                            </ul>
                                        </c:forEach>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-lg btn-block btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</nav>

</body>
</html>
